﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using Business.DA;
using Business.VOL;
using System.Data;

namespace Business.BLL
{
    class NhaCungCapBL
    {
        private DataAccess dataAccess;
        public NhaCungCapBL()
        {
            dataAccess = new DataAccess();
        }

        //Thêm
        public bool insertNhaCungCap(NhaCungCap obj)
        {
            SqlParameter[] param = new SqlParameter[4];
            param[0] = new SqlParameter("@TenNhaCungCap", SqlDbType.Int) { Value = obj.TenNhaCungCap };
            param[1] = new SqlParameter("@DiaChi", SqlDbType.DateTime) { Value = obj.DiaChi };
            param[2] = new SqlParameter("@DienThoai", SqlDbType.VarChar) { Value = obj.DienThoai };
            param[3] = new SqlParameter("@Email", SqlDbType.Bit) { Value = obj.Email };

            string strSql = "INSERT INTO tbl_NhaCungCap(TenNhaCungCap,DiaChi,DienThoai,Email) VALUES (@TenNhaCungCap,@DiaChi,@DienThoai,@Email)";
            dataAccess.Execute(strSql);

            return true;
        }

        //Xóa
        public bool deleteNhaCungCap(NhaCungCap obj)
        {
            SqlParameter[] param = new SqlParameter[1];
            param[0] = new SqlParameter("@MaNhaCungCap", SqlDbType.Int) { Value = obj.MaNhaCungCap };

            string strSql = "DELETE FROM tbl_NhaCungCap WHERE MaNhaCungCap = @MaNhaCungCap";
            dataAccess.Execute(strSql);
            return true;
        }

        //Sửa
        public bool updateNhaCungCap(NhaCungCap obj)
        {
            SqlParameter[] param = new SqlParameter[6];
            param[0] = new SqlParameter("@TenNhaCungCap", SqlDbType.Int) { Value = obj.TenNhaCungCap };
            param[1] = new SqlParameter("@DiaChi", SqlDbType.DateTime) { Value = obj.DiaChi };
            param[2] = new SqlParameter("@DienThoai", SqlDbType.VarChar) { Value = obj.DienThoai };
            param[3] = new SqlParameter("@Email", SqlDbType.Bit) { Value = obj.Email };
            param[4] = new SqlParameter("@MaNhaCungCap", SqlDbType.Int) { Value = obj.MaNhaCungCap };

            string strSql = "UPDATE tbl_NhaCungCap SET " +
                            "TenNhaCungCap = @TenNhaCungCap, " +
                            "DiaChi = @DiaChi, " +
                            "DienThoai = @DienThoai, " +
                            "Email = @Email " +
                            "WHERE MaNhaCungCap = @MaNhaCungCap";
            dataAccess.Execute(strSql);
            return true;
        }

        //Tìm
        public DataTable searchIDNhaCungCap(NhaCungCap obj)
        {
            SqlParameter[] param = new SqlParameter[1];
            param[0] = new SqlParameter("@MaNhaCungCap", SqlDbType.Int) { Value = obj.MaNhaCungCap };

            string strSql = "SELECT * FROM tbl_NhaCungCap WHERE MaNhaCungCap = @MaNhaCungCap";
            return dataAccess.GetData(strSql, param);
        }
    }
}
